﻿Imports Microsoft.Practices.EnterpriseLibrary.Data
Imports Seuss.EnterpriseLibrary.DataAccess
Imports Seuss.EnterpriseLibrary.BusinessLogic
Imports System.Web
Imports System.Data

Partial Class Consulta_DO_CursoAsig_ForoRes
    Inherits System.Web.UI.Page
    Dim nCurGruCodigo As String
    Dim nivelForo As String
    Dim foroactual As String = ""
    Dim rpta As String
    Dim del As String
    Dim nForo As String

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Request.QueryString("nCurGruCodigo") Is Nothing Or Request.QueryString("nCurGruCodigo") Is String.Empty Or _
        Request.QueryString("nivelforo") Is Nothing Or Request.QueryString("nivelforo") Is String.Empty Then
            If Session("nCurGruCodigo") Is Nothing Or Session("nCurGruCodigo") Is String.Empty Or _
            Session("nivelforo") Is Nothing Or Session("nivelforo") Is String.Empty Then
                Response.Redirect("DO_ListaCursAsig.aspx")
            Else
                nCurGruCodigo = Session("nCurGruCodigo")
                nivelForo = Session("nivelforo")
            End If
        Else
            Session("nCurGruCodigo") = Request.QueryString("nCurGruCodigo")
            Session("nivelforo") = Request.QueryString("nivelforo")
            nCurGruCodigo = Request.QueryString("nCurGruCodigo")
            nivelForo = Request.QueryString("nivelforo")
        End If
        rpta = Request.QueryString("rpta")
        del = Request.QueryString("del")

        If Request.QueryString("nForo") Is Nothing Or Request.QueryString("nForo") Is String.Empty Then
            If Session("nForo") Is Nothing Or Session("nForo") Is String.Empty Then
                nForo = Session("nivelforo")
                Session("nForo") = nForo
            Else
                nForo = Session("nForo")
            End If
        Else
            nForo = Request.QueryString("nForo")
            Session("nForo") = Request.QueryString("nForo")
        End If

        Response.Expires = -1
        Response.AddHeader("Pragma", "no-cache")
        Response.AddHeader("cache-control", "private")
        Response.CacheControl = "no-cache"
        lnkRegresar_3.HRef = "./DO_CursoAsig_Foro.aspx?nCurGruCodigo=" + nCurGruCodigo
        lnkRegresar_4.HRef = "./DO_CursoAsig_Foro.aspx?nCurGruCodigo=" + nCurGruCodigo

        If Not Page.IsPostBack Then
            If rpta = "1" Then
                panelresponder.Visible = True
                panelbotones.Visible = False
            Else
                panelresponder.Visible = False
                panelbotones.Visible = True
            End If
            If del = "1" Then
                EliminaRpta()
            End If
            CargaRespuestasForos()
            Using Seguridad As New BLL_Administracion
                Seguridad.Set_Transaccion_Insert(Nothing, 100401, IdentityUser.UserCode, My.Request.UserHostAddress.ToString, CrearXMLTransaccion("Consulta Pagina Movil", "/Pagina|" + My.Request.Url.Segments(My.Request.Url.Segments.Length - 1).ToString))
            End Using
        End If
    End Sub

    Private Sub CargaRespuestasForos()
        Dim DivPrincipal As New StringBuilder
        Dim ldrforoactual As New List(Of IDataReader)

        Using ObjPool As New PoolDbCommand()
            Dim Objgrupo As New DAL_Kiosco(ObjPool.Database)
            ObjPool.AddDbCommand(Objgrupo.Get_ForoCampus_By_nCurGruCodigo_nForoPadre_nForoPrincipal(nCurGruCodigo, "0", "-1", 0), PoolDbCommand.PoolDbCommandResultType.Query)
            ObjPool.Pooling(Nothing, ldrforoactual, True)
        End Using
        While ldrforoactual(0).Read
            If ldrforoactual(0).Item("nForo") = nivelForo.ToString Then
                foroactual = ldrforoactual(0).Item("tForoDesc")
                Session("estado") = ldrforoactual(0).Item("estado")
            End If
        End While
        If Session("estado") = "Activo" Then
            btndesactivar.Text = "Desactivar"
        Else
            btndesactivar.Text = "Activar"
        End If
        Dim ldrforos As New List(Of IDataReader)
        Using ObjPool As New PoolDbCommand()
            Dim Objgrupo As New DAL_Kiosco(ObjPool.Database)
            ObjPool.AddDbCommand(Objgrupo.Get_ForoCampus_By_nCurGruCodigo_nForoPadre_nForoPrincipal(nCurGruCodigo, "-1", nivelForo, 0), PoolDbCommand.PoolDbCommandResultType.Query)
            ObjPool.Pooling(Nothing, ldrforos, True)
        End Using
        ldrforoactual(0).Read()
        Dim nivel As String = ""
        DivPrincipal.Append("<table width=""100%"" style=""font-size:12px; text-align:left;"">")
        DivPrincipal.Append("<tr><td style=""font-size:13px;"" colspan=""3"">Tema: <strong>" & foroactual & "<strong></td></tr>")
        DivPrincipal.Append("<tr><td><br/></td></tr><tr style=""font-size:12px;""><td style=""padding-left: 5px; border-bottom: solid 1px #ccc;"">Respuestas </td>")
        DivPrincipal.Append("<td style=""border-bottom: solid 1px #ccc; width:30%; text-align:center;"">Fecha</td><td style=""text-align: center; border-bottom: solid 1px #ccc;""></td></tr>")
        While ldrforos(0).Read
            nivel = (ldrforos(0).Item("nivel") - 15).ToString
            DivPrincipal.Append("<tr><td style=""border-bottom: solid 1px #ccc; text-align:left; padding-left:" & nivel & "px"">")
            DivPrincipal.Append("<img width=""15px"" height=""15px"" src=""../imagenes/Ok2.gif"" />&nbsp;&nbsp;" & "<a href=""Do_CursoAsig_ForoRes.aspx?rpta=1&nForo=" & ldrforos(0).Item("nForo") & """>" & ldrforos(0).Item("tForoDesc") & "</a><br/>" & "<font style=""font-size:10px;"">" & ldrforos(0).Item("ALIAS") & "</font>")
            DivPrincipal.Append("</td><td style=""border-bottom: solid 1px #ccc; width:30%; text-align:center;"">")
            DivPrincipal.Append(ldrforos(0).Item("FECHA"))
            DivPrincipal.Append("</td><td style=""border-bottom: solid 1px #ccc;""><a style=""text-decoration:none"" href=""./Do_CursoAsig_ForoRes.aspx?del=1&nForo=" & ldrforos(0).Item("nForo") & """ ><img src='../Imagenes/cerrar.jpg' border='0'/></a></td></tr>")
        End While
        DivPrincipal.Append("</table>")
        lblcontenido.Text = DivPrincipal.ToString
        ldrforos(0).Close()
        ldrforos(0) = Nothing
    End Sub

    Protected Sub btnresponder_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnresponder.Click
        panelresponder.Visible = True
        panelbotones.Visible = False
        'Session("nForo") = Session("nivelforo")
        Response.Redirect("Do_CursoAsig_ForoRes.aspx?rpta=1&nForo=" & Session("nivelforo"))
    End Sub

    Protected Sub btnrespuesta_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnrespuesta.Click
        Using ObjPool As New PoolDbCommand()
            Dim Objgrupo As New DAL_Kiosco(ObjPool.Database)
            ObjPool.AddDbCommand(Objgrupo.Ins_ForoCampus(nCurGruCodigo, txtrespuesta.Text, IdentityUser.UserCode, nForo), PoolDbCommand.PoolDbCommandResultType.NonQuery)
            If ObjPool.Pooling() Then
                Using Seguridad As New BLL_Administracion
                    Seguridad.Set_Transaccion_Insert(Nothing, 100413, IdentityUser.UserCode, My.Request.UserHostAddress.ToString, CrearXMLTransaccion("Respuesta de Foro", "/nCurGurCodigo|" + nCurGruCodigo + "/nPadre|" + nForo))
                End Using
            End If
        End Using
        panelresponder.Visible = False
        panelbotones.Visible = True
        txtrespuesta.Text = ""
        Response.Redirect("Do_CursoAsig_ForoRes.aspx?rpta=0&nForo=" & Session("nivelforo"))
    End Sub


    Private Sub EliminaRpta()

        Using ObjPool As New PoolDbCommand()
            Dim Objgrupo As New DAL_Kiosco(ObjPool.Database)
            ObjPool.AddDbCommand(Objgrupo.Del_ForoCampus_By_nCurGruCodigo_nForo(nCurGruCodigo, nForo), PoolDbCommand.PoolDbCommandResultType.NonQuery)
            If ObjPool.Pooling() Then
                Using Seguridad As New BLL_Administracion
                    Seguridad.Set_Transaccion_Insert(Nothing, 100414, IdentityUser.UserCode, My.Request.UserHostAddress.ToString, CrearXMLTransaccion("Eliminar Foro", "/nCurGurCodigo|" + nCurGruCodigo + "/nForo|" + nForo))
                End Using
            End If
        End Using
        Response.Redirect("Do_CursoAsig_ForoRes.aspx?del=0&nForo=" & Session("nivelforo"))
    End Sub

    Protected Sub btncancelar_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btncancelar.Click
        txtrespuesta.Text = ""
        panelresponder.Visible = False
        panelbotones.Visible = True
    End Sub

    Protected Sub btneliminar_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btneliminar.Click

        Using ObjPool As New PoolDbCommand()
            Dim Objgrupo As New DAL_Kiosco(ObjPool.Database)
            ObjPool.AddDbCommand(Objgrupo.Del_ForoCampus_By_nCurGruCodigo_nForo(nCurGruCodigo, nivelForo), PoolDbCommand.PoolDbCommandResultType.NonQuery)
            If ObjPool.Pooling() Then
                Using Seguridad As New BLL_Administracion
                    Seguridad.Set_Transaccion_Insert(Nothing, 100414, IdentityUser.UserCode, My.Request.UserHostAddress.ToString, CrearXMLTransaccion("Eliminar Foro", "/nCurGruCodigo|" + nCurGruCodigo + "/Foro|" + nivelForo))
                End Using
            End If
        End Using
        Response.Redirect("./DO_CursoAsig_Foro.aspx?nCurGruCodigo=" + nCurGruCodigo)
    End Sub

    Protected Sub btndesactivar_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btndesactivar.Click
        Dim NuevoEstado As Integer = IIf(Session("estado") = "Activo", 0, 1)

        Using ObjPool As New PoolDbCommand()
            Dim Objgrupo As New DAL_Kiosco(ObjPool.Database)
            ObjPool.AddDbCommand(Objgrupo.Upd_ForoCampus_By_nCurGruCodigo_nForo(nCurGruCodigo, Session("nivelforo"), NuevoEstado), PoolDbCommand.PoolDbCommandResultType.NonQuery)
            If ObjPool.Pooling() Then
                Using Seguridad As New BLL_Administracion
                    Seguridad.Set_Transaccion_Insert(Nothing, 100413, IdentityUser.UserCode, My.Request.UserHostAddress.ToString, CrearXMLTransaccion("Actualiza Estado Foro", "/nCurGruCodigo|" + nCurGruCodigo + "/ForoPadre|0"))
                End Using
            End If
        End Using
        Session("estado") = ""
        
        Response.Redirect("./DO_CursoAsig_ForoRes.aspx?nForo=" + Session("nivelforo"))
    End Sub
End Class